<template>
	<view>
		<view class="mt24">
			<u-swipe-action>
				<u-swipe-action-item :options="options1" @click="delAddress" :name='item.id'  v-for="(item,index) in address_list" :key="item.id">
					<view class="bac_f border_f8 pl30 pr30 pt30 pb30 dis_flex">
						<view class="">
							<view class="dis_f">
								<view style="max-width: 500rpx;" class="fz28">{{item.name}}</view>
								<view class="ml24 fz28">{{item.phone}}</view>
								<view v-show="item.default==1" class="w64 lh40 fz20 ml24 tf_4537 tac radius4" style="background: rgba(241, 69, 55, 0.1);padding: 0 6rpx;">默认</view>
							</view>
							<view class="tf_999 pt10 dis_f fz26" style="max-width: 604rpx;">{{item.address1}}{{item.address2}}</view>
						</view>
						<view class="" @click="editAddress(item)"><image class="w28" src="../../static/image/bianji.png" mode="widthFix"></image></view>
					</view>
				</u-swipe-action-item>
			</u-swipe-action>
			<view class="ml30 mr30">
				<u-gap height="1" bgColor="#e7e7e7"></u-gap>
			</view>
		</view>
		<view class="dis_f jc p_f h136 w bac_f bs4" @click="addAddress">
			<view class=""><view class="w690 btn radius8 tf h88 dis_f jc fz32">新增地址</view></view>
		</view>
	</view>
</template>

<script>
	import {
		addressList,addressDel
	} from "@/config/api.js";
export default {
	data() {
		return {
			address_list:[],
			options1: [
				{
					text: '删除',
				}
			]
		};
	},
	onLoad() {
		this.getAllAddress()
		uni.$on('refreshData',() => {
				this.getAllAddress();
		})
	},
	methods: {
		//修改地址
		editAddress(e) {
			let page_obj = encodeURIComponent(JSON.stringify(e))
			console.log(page_obj);
			uni.navigateTo({
				url: '../../pages/editAddress/editAddress?page_obj=' + page_obj,
			})
		},
		//新增地址
		addAddress(){
			uni.navigateTo({
				url:'../../pages/addNewAddress/addNewAddress'
			})
		},
		//删除地址
		delAddress(e){
			console.log(e);
			addressDel({id:e.name}).then(res=>{
				console.log(res);
				this.getAllAddress()
			})
		},
		//获取地址
		getAllAddress(){
			addressList().then(res=>{
				console.log(res);
				this.address_list = res
			})
		}
	}
};
</script>

<style></style>
